local skel = fk.CreateSkill {
  name = "emo__moyinn",
}

Fk:loadTranslationTable{
  ["emo__moyinn"] = "魔音", -- 存在同名
  [":emo__moyinn"] = "每轮回合内外各限一次，一名角色使用【杀】造成伤害后，你可以摸一张牌并判定，若结果为："..
  "<font color='red'>♥</font>，受伤角色失去1点体力；"..
  "<font color='red'>♦</font>，受伤角色弃置两张牌；"..
  "♠，伤害来源重置武将牌或一个技能；"..
  "♣，伤害来源摸两张牌。",

  ["#emo__moyinn-choice"] = "魔音：选择重置武将牌或一个技能",
  ["#emo__moyinn_reset"] = "重置武将牌",
}

skel:addEffect(fk.Damage, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(skel.name) and data.card and data.card.trueName == "slash" and target and not target.dead then
      if player == player.room.current then
        return player:getMark("emo__moyinn_inside-round") == 0
      else
        return player:getMark("emo__moyinn_outside-round") == 0
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player == room.current then
      room:setPlayerMark(player, "emo__moyinn_inside-round", 1)
    else
      room:setPlayerMark(player, "emo__moyinn_outside-round", 1)
    end
    player:drawCards(1, skel.name)
    if player.dead then return end
    local judge = {
      who = player,
      reason = skel.name,
      pattern = ".",
    }
    room:judge(judge)
    if not judge.card then return end
    local to = data.to
    if judge.card.suit == Card.Heart then
      if not to.dead then
        room:loseHp(to, 1, skel.name)
      end
    elseif judge.card.suit == Card.Diamond then
      if not to.dead and not to:isNude() then
        room:askToDiscard(to, {
          min_num = 2,
          max_num = 2,
          include_equip = true,
          skill_name = skel.name,
          cancelable = false,
        })
      end
    elseif judge.card.suit == Card.Club then
      if not target.dead then
        target:drawCards(2, skel.name)
      end
    elseif judge.card.suit == Card.Spade then
      if not target.dead then
        local choices = {}
        if target.chained or not target.faceup then
          table.insert(choices, "#emo__moyinn_reset")
        end
        table.insertTable(choices, target:getSkillNameList())
        if #choices == 0 then return end
        local choice = room:askToChoice(target, {
          choices = choices, skill_name = skel.name, prompt = "#emo__moyinn-choice",
        })
        if choice == "#emo__moyinn_reset" then
          target:reset()
        else
          target:clearSkillHistory(choice)
        end
      end
    end
  end,
})

return skel
